package Song.Han.Demo01;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

/*
    InputStreamReader:使用指定的charset将要写入流中的字节解码成字符
*/
public class Demo02InputStreamReader {
    public static void main(String[] args) throws IOException {
        read_utf_8();
        read_gbk();
    }

    private static void read_gbk() throws IOException{
        InputStreamReader isr = new InputStreamReader(new FileInputStream("E:\\IDeaProject\\Day15\\src\\Song\\Han\\Demo01\\gbk.txt"),"gbk");

        int len = 0;
        while((len = isr.read()) != -1){
            System.out.print((char)len);
        }
        isr.close();

    }

    private static void read_utf_8() throws IOException {
        InputStreamReader isr = new InputStreamReader(new FileInputStream("E:\\IDeaProject\\Day15\\src\\Song\\Han\\Demo01\\utf_8.txt"));

        int len = 0;
        while((len = isr.read()) != -1){
            System.out.print((char)len);
        }
        isr.close();
    }
}
